<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>移动零 - 算法详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #282c34;
            color: #abb2bf;
            border-radius: 8px;
            overflow-x: auto;
        }
        .code-block code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
        }
        .keyword { color: #c678dd; }
        .function { color: #61afef; }
        .string { color: #98c379; }
        .number { color: #d19a66; }
        .comment { color: #5c6370; font-style: italic; }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .fade-in {
            animation: fadeIn 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-4xl mx-auto text-center fade-in">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                <i class="fas fa-arrows-alt-h mr-4"></i>移动零
            </h1>
            <p class="text-xl md:text-2xl opacity-90 leading-relaxed">
                双指针算法的优雅实践，在原地操作中展现算法之美
            </p>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Problem Description Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
            <div class="flex items-center mb-6">
                <div class="bg-purple-100 rounded-full p-3 mr-4">
                    <i class="fas fa-question-circle text-purple-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">题目描述</h2>
            </div>
            <div class="text-gray-700 leading-relaxed">
                <p class="text-lg mb-4">
                    <span class="drop-cap">给</span>定一个数组，将所有 0 移动到数组末尾，同时保持非零元素的相对顺序。
                </p>
                <div class="bg-gray-50 rounded-lg p-6 mb-6">
                    <p class="font-semibold text-gray-800 mb-2">示例：</p>
                    <div class="flex items-center justify-center space-x-4">
                        <div class="text-center">
                            <p class="text-sm text-gray-600 mb-2">输入</p>
                            <div class="bg-white px-4 py-2 rounded border-2 border-gray-300">
                                <code class="text-lg font-mono">[0, 1, 0, 3, 12]</code>
                            </div>
                        </div>
                        <i class="fas fa-arrow-right text-2xl text-purple-500"></i>
                        <div class="text-center">
                            <p class="text-sm text-gray-600 mb-2">输出</p>
                            <div class="bg-white px-4 py-2 rounded border-2 border-purple-300">
                                <code class="text-lg font-mono">[1, 3, 12, 0, 0]</code>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="grid md:grid-cols-2 gap-4">
                    <div class="bg-red-50 rounded-lg p-4 border-l-4 border-red-400">
                        <p class="font-semibold text-red-700 mb-1">
                            <i class="fas fa-exclamation-triangle mr-2"></i>要求一
                        </p>
                        <p class="text-red-600">必须在原数组上操作，不能使用额外数组</p>
                    </div>
                    <div class="bg-yellow-50 rounded-lg p-4 border-l-4 border-yellow-400">
                        <p class="font-semibold text-yellow-700 mb-1">
                            <i class="fas fa-tachometer-alt mr-2"></i>要求二
                        </p>
                        <p class="text-yellow-600">尽量减少操作次数</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Core Concept Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
            <div class="flex items-center mb-6">
                <div class="bg-blue-100 rounded-full p-3 mr-4">
                    <i class="fas fa-lightbulb text-blue-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">核心算法</h2>
            </div>
            <div class="text-center py-8">
                <div class="inline-block bg-gradient-to-r from-blue-500 to-purple-600 text-white px-8 py-4 rounded-full text-2xl font-bold shadow-lg">
                    <i class="fas fa-hand-point-right mr-3"></i>双指针算法
                </div>
            </div>
        </div>

        <!-- Solution Approach Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
            <div class="flex items-center mb-6">
                <div class="bg-green-100 rounded-full p-3 mr-4">
                    <i class="fas fa-route text-green-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">解题思路</h2>
            </div>
            <div class="space-y-6">
                <div class="bg-gradient-to-r from-green-50 to-blue-50 rounded-lg p-6">
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">
                        <i class="fas fa-arrows-alt-h mr-2 text-green-600"></i>双指针策略
                    </h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <div>
                                <code class="bg-gray-100 px-2 py-1 rounded text-purple-600 font-mono">non_zero_pos</code>
                                <span class="text-gray-700">：指向下一个非零元素应放置的位置</span>
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <div>
                                <code class="bg-gray-100 px-2 py-1 rounded text-purple-600 font-mono">i</code>
                                <span class="text-gray-700">：遍历整个数组的指针</span>
                            </div>
                        </li>
                    </ul>
                </div>

                <!-- Algorithm Visualization -->
                <div class="bg-gray-50 rounded-lg p-6">
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">
                        <i class="fas fa-project-diagram mr-2 text-blue-600"></i>算法流程图
                    </h3>
                    <div class="mermaid">
                        graph TD
                            A[开始] --> B[初始化 non_zero_pos = 0]
                            B --> C{遍历数组}
                            C --> D{当前元素是否为0?}
                            D -->|是| C
                            D -->|否| E[交换元素到 non_zero_pos 位置]
                            E --> F[non_zero_pos++]
                            F --> C
                            C -->|遍历结束| G[算法完成]
                            
                            style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                            style G fill:#48bb78,stroke:#fff,stroke-width:2px,color:#fff
                            style D fill:#f6e05e,stroke:#333,stroke-width:2px
                    </div>
                </div>

                <div class="grid md:grid-cols-2 gap-4">
                    <div class="bg-blue-50 rounded-lg p-4 text-center">
                        <i class="fas fa-clock text-blue-600 text-3xl mb-2"></i>
                        <p class="font-semibold text-gray-800">时间复杂度</p>
                        <p class="text-2xl font-bold text-blue-600">O(n)</p>
                    </div>
                    <div class="bg-purple-50 rounded-lg p-4 text-center">
                        <i class="fas fa-memory text-purple-600 text-3xl mb-2"></i>
                        <p class="font-semibold text-gray-800">空间复杂度</p>
                        <p class="text-2xl font-bold text-purple-600">O(1)</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Code Implementation Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
            <div class="flex items-center mb-6">
                <div class="bg-orange-100 rounded-full p-3 mr-4">
                    <i class="fas fa-code text-orange-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">示例代码</h2>
            </div>
            <div class="code-block p-6">
                <pre><code><span class="keyword">def</span> <span class="function">moveZeroes</span>(nums):
    <span class="comment"># 初始化非零元素的位置指针</span>
    non_zero_pos = <span class="number">0</span>
    
    <span class="comment"># 遍历数组</span>
    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="function">range</span>(<span class="function">len</span>(nums)):
        <span class="keyword">if</span> nums[i] != <span class="number">0</span>:
            <span class="comment"># 将非零元素交换到前面</span>
            nums[non_zero_pos], nums[i] = nums[i], nums[non_zero_pos]
            non_zero_pos += <span class="number">1</span></code></pre>
            </div>
        </div>

        <!-- Key Insights -->
        <div class="mt-12 bg-gradient-to-r from-purple-100 to-pink-100 rounded-2xl p-8">
            <h3 class="text-2xl font-bold text-gray-800 mb-4">
                <i class="fas fa-star mr-2 text-yellow-500"></i>算法精髓
            </h3>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="text-center">
                    <i class="fas fa-exchange-alt text-4xl text-purple-600 mb-3"></i>
                    <h4 class="font-semibold text-gray-800 mb-2">原地操作</h4>
                    <p class="text-gray-600">不需要额外空间，直接在原数组上完成操作</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-sort text-4xl text-pink-600 mb-3"></i>
                    <h4 class="font-semibold text-gray-800 mb-2">保持顺序</h4>
                    <p class="text-gray-600">非零元素的相对顺序保持不变</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-rocket text-4xl text-indigo-600 mb-3"></i>
                    <h4 class="font-semibold text-gray-800 mb-2">最优效率</h4>
                    <p class="text-gray-600">一次遍历完成，时间复杂度最优</p>
                </div>
            </div>
        </div>
    </div>

    <script>
        mermaid.initialize({ 
            startOnLoad: true,
            theme: 'default',
            themeVariables: {
                primaryColor: '#667eea',
                primaryTextColor: